package com.baizhi.service.impl;

import com.baizhi.dao.AuctionDao;
import com.baizhi.entity.Auction;
import com.baizhi.service.AuctionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service("auctionService")
public class AuctionServiceImpl implements AuctionService {
    private AuctionDao auctionDao;
    @Autowired
    public void setAuctionDao(AuctionDao auctionDao) {
        this.auctionDao = auctionDao;
    }

    @Override
    public int insertAuction(Auction auction) {
        int i = auctionDao.insertAuction(auction);
        return i;
    }

    @Override
    public int deleteAuction(Integer auctionId) {
        int i = auctionDao.deleteAuction(auctionId);
        return i;
    }

    @Override
    public int updateAuction(Auction auction) {
        int i = auctionDao.updateAuction(auction);
        return i;
    }

    @Override
    public Auction selectById(Integer auctionId) {
        Auction auction = auctionDao.selectById(auctionId);
        return auction;
    }

    @Override
    public PageInfo<Auction> selectAll(String auctionName, String auctionDesc, Date auctionStartTime, Date auctionEndTime, Double auctionStartPrice, Integer pageNum, Integer pageSize) {
        //使用分页插件进行查询
        //首先 设置分页方式  然后将其下面紧邻的那一行的查询结果进行分页
        PageHelper.startPage(pageNum,pageSize);
        List<Auction> list = auctionDao.selectAll(auctionName, auctionDesc, auctionStartTime, auctionEndTime, auctionStartPrice);
        //最后利用PageInfo<Auction>的有参构造 传入上一步查询的结果list集合 创建一个pageInfo对象
        // 此对象内有以后页面所需要用到的所有信息
        PageInfo<Auction> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}
